package com.kwedding.util;

public class BackJson {

	/**
	 * 请求成功json处理
	 * 
	 * @param body
	 * @return
	 */
	public static <T> JsonBackBase<T> successObj(T body) {
		JsonBackBase<T> backEntity = new JsonBackBase<T>();
		backEntity.setResult(body);
		return backEntity;
	}
	
	public static <T> JsonBackBase<T> getResponse(T body,Integer code,String msg) {
		JsonBackBase<T> backEntity = new JsonBackBase<T>();
		backEntity.setResult(body);
		backEntity.setCode(code);
		backEntity.setMsg(msg);
		return backEntity;
	}
	
	public static <T> JsonBackBase<T> getResponse(T body,Integer code) {
		JsonBackBase<T> backEntity = new JsonBackBase<T>();
		backEntity.setResult(body);
		backEntity.setCode(code);
		backEntity.setMsg(Response.getMsg(code));
		return backEntity;
	}	

	/**
	 * 请求成功json处理
	 * 
	 * @param body
	 * @return
	 */
	public static JsonBack success() {
		JsonBack backEntity = new JsonBack();
		return backEntity;
	}

	/**
	 * 请求失败json处理
	 * 
	 * @param body
	 * @return
	 */
	public static String error(int errorCode, String msg) {
		JsonBack backEntity = new JsonBack();
		backEntity.setCode(errorCode);
		backEntity.setMsg(msg);
		return GsonUtil.objectToJsonStr(backEntity);
	}
}
